<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>全部申请</title>
<link rel="stylesheet" href="../public/layui/css/layui.css" media="all">
<script src="../public/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<%if(session.getAttribute("user")==null){ %>
    <script>
		window.top.location.replace("../login.jsp");
	</script>
<%}%>
<div>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
		<legend><h2>所有的各种申请</h2></legend>
	</fieldset>
<!-- 加班申请 -->
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
		<legend><h4  style="color:#c2c2c2"><span id="applytype1" style="color:#393D49"></span></h4></legend>
	</fieldset>
	<table class="layui-hide" id="demo1" lay-filter="form1"></table>
<!-- 请假旷工申请 -->	
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
		<legend><h4  style="color:#c2c2c2"><span id="applytype2" style="color:#393D49"></span></h4></legend>
	</fieldset>
	<table class="layui-hide" id="demo2" lay-filter="form2"></table>
<!-- 提成申请 -->	
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
		<legend><h4  style="color:#c2c2c2"><span id="applytype3" style="color:#393D49"></span></h4></legend>
	</fieldset>
	<table class="layui-hide" id="demo3" lay-filter="form3"></table>
<!-- 奖金申请 -->	
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
		<legend><h4  style="color:#c2c2c2"><span id="applytype4" style="color:#393D49"></span></h4></legend>
	</fieldset>
	<table class="layui-hide" id="demo4" lay-filter="form4"></table>
	
	<!-- 头部工具栏1 -->
	<script type="text/html" id="search1">
 		 
		指定显示
		<div class="layui-inline layui-form">
	  	  <select id="condition1" name="condition">
        	<option value="" selected>请选择</option>
			<option value="0">待审核的</option>
        	<option value="1">审核通过的</option>
			<option value="2">审核不通过的</option>
		  </select>
	 	 </div>
  		 <button class="layui-btn" name="search" data-type="reload"  lay-event="search">确认</button>
	</script>
<!-- 	行级工具栏1 -->
	<script type="text/html" id="statusTpl">
  		{{#  if(d.status == 0){ }}
				<span style="color:#01AAED;">待处理</span>
   	 			<div  class="layui-btn-group">
					<button class="layui-btn layui-btn-xs" lay-event="agree">同意</button>
					<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refuse">拒绝</button>
				</div>
  		{{#  } else if(d.status == 1){ }}
   	 			<div style="color:#5FB878; ">申请已通过</div>
				
  		{{#  } else { }}
   	 			<div style="color:#FF5722;">申请已拒绝</div>
					
		{{#  } }}
	</script>
	<!-- 头部工具栏2 -->
	<script type="text/html" id="search2">
 		 
		指定显示
		<div class="layui-inline layui-form">
	  	  <select id="condition2" name="condition">
        	<option value="" selected>请选择</option>
			<option value="0">待审核的</option>
        	<option value="1">审核通过的</option>
			<option value="2">审核不通过的</option>
		  </select>
	 	 </div>
  		 <button class="layui-btn" name="search" data-type="reload"  lay-event="search">确认</button>
	</script>
<!-- 	行级工具栏2 -->
	<script type="text/html" id="statusTpl2">
  		{{#  if(d.status == 0){ }}
				<span style="color:#01AAED;">待处理</span>
   	 			<div  class="layui-btn-group">
					<button class="layui-btn layui-btn-xs" lay-event="agree">同意</button>
					<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refuse">拒绝</button>
				</div>
  		{{#  } else if(d.status == 1){ }}
   	 			<div style="color:#5FB878; ">申请已通过</div>
				
  		{{#  } else { }}
   	 			<div style="color:#FF5722;">申请已拒绝</div>
					
		{{#  } }}
	</script>
	<!-- 头部工具栏3 -->
	<script type="text/html" id="search3">
 		 
		指定显示
		<div class="layui-inline layui-form">
	  	  <select id="condition3" name="condition">
        	<option value="" selected>请选择</option>
			<option value="0">待审核的</option>
        	<option value="1">审核通过的</option>
			<option value="2">审核不通过的</option>
		  </select>
	 	 </div>
  		 <button class="layui-btn" name="search" data-type="reload"  lay-event="search">确认</button>
	</script>
<!-- 	行级工具栏3 -->
	<script type="text/html" id="statusTpl3">
  		{{#  if(d.status == 0){ }}
				<span style="color:#01AAED;">待处理</span>
   	 			<div  class="layui-btn-group">
					<button class="layui-btn layui-btn-xs" lay-event="agree">同意</button>
					<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refuse">拒绝</button>
				</div>
  		{{#  } else if(d.status == 1){ }}
   	 			<div style="color:#5FB878; ">申请已通过</div>
				
  		{{#  } else { }}
   	 			<div style="color:#FF5722;">申请已拒绝</div>
					
		{{#  } }}
	</script>
	<!-- 头部工具栏4 -->
	<script type="text/html" id="search4">
 		 
		指定显示
		<div class="layui-inline layui-form">
	  	  <select id="condition4" name="condition">
        	<option value="" selected>请选择</option>
			<option value="0">待审核的</option>
        	<option value="1">审核通过的</option>
			<option value="2">审核不通过的</option>
		  </select>
	 	 </div>
  		 <button class="layui-btn" name="search" data-type="reload"  lay-event="search">确认</button>
	</script>
<!-- 	行级工具栏4 -->
	<script type="text/html" id="statusTpl4">
  		{{#  if(d.status == 0){ }}
				<span style="color:#01AAED;">待处理</span>
   	 			<div  class="layui-btn-group">
					<button class="layui-btn layui-btn-xs" lay-event="agree">同意</button>
					<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="refuse">拒绝</button>
				</div>
  		{{#  } else if(d.status == 1){ }}
   	 			<div style="color:#5FB878; ">申请已通过</div>
				
  		{{#  } else { }}
   	 			<div style="color:#FF5722;">申请已拒绝</div>
					
		{{#  } }}
	</script>
	<script type="text/javascript">
	layui.use(['laypage','table', 'jquery','layer','form'],function(){
		$ = layui.jquery;
		var table = layui.table;
		var layer = layui.layer;
		var form = layui.form;
		var laypage = layui.laypage;
//加班		
// 		laypage.render({
// 		    elem: 'demo1' //注意，这里的 test1 是 ID，不用加 # 号
// 			,limit: 5
// 			,limits:[5,10,15,20]
// 		});
		var tableIns1 = table.render({
			done: function(res, curr, count){
				if(res.data[0].applytype == 'inputOvertime'){
					document.getElementById("applytype1").innerText = "加班申请";
				}else if(res.data[0].applytype == 'inputPunishing'){
					document.getElementById("applytype2").innerText = "请假旷工申请";
				}else if(res.data[0].applytype == 'inputCommission'){
					document.getElementById("applytype3").innerText = "提成申请";
				}else if(res.data[0].applytype == 'inputBonus'){
					document.getElementById("applytype4").innerText = "奖金申请";
				}
			}
			,elem: '#demo1'
		    ,height: 350
		    ,url: '../HumanServlet?button=1&applytype=inputOvertime' //数据接口
	    	,toolbar: '#search1'
		    ,page: true //开启分页
		    ,limit: 5
			,limits:[5,20,50]
		    ,defaultToolbar:["print"]
		    ,cols: [[ //表头
			      {field: 'applyid', title: '申请编号', width:120, sort: true,fixed: 'left'}
			      ,{field: 'applicant', title: '申请人', width:100}
			      ,{field: 'applytime', title: '申请提交时间', width: 180, sort: true}
			      ,{field: 'operater', title: ' 处理对象', width:100}
			      ,{field: 'overtime', title: '普通加班时长（单位小时）', width:200} 
			      ,{field: 'weekovertime', title: '周末加班时长（单位小时）', width: 200}
			      ,{field: 'festovertime', title: '节假日加班时长（单位小时）', width: 220}
			      ,{field: 'applydescribe', title: '申请描述', width: 250}
			      ,{field: 'handle', title: '审批人', width: 100}
			      ,{field: 'handletime', title: '审批时间', width: 180, sort: true}
			      ,{field: 'status', title: '审批状态', width:150, templet:'#statusTpl',fixed: 'right'}
			    ]]
		});
		// 顶部工具栏事件
		  table.on('toolbar(form1)', function(obj){
//			  var checkStatus = table.checkStatus(obj.config.id);
			  var data = obj.data;
	    	  var condition = $('#condition1');
// 	    	  var Condition = document.getElementById("condition");
	    	  if(condition.val()==""){
	    		  layer.msg("显示全部加班申请");
	    	  }else if(condition.val()=="0"){
	    		  layer.msg("显示待审核的加班申请");
	    	  }else if(condition.val()=="1"){
	    		  layer.msg("显示审核通过的加班申请");
	    	  }else if(condition.val()=="2"){
	    		  layer.msg("显示审核不通过的加班申请");
	    	  }
	    	  tableIns1.reload({
	    		  url: '../HumanServlet?button=1&applytype=inputOvertime'
				  ,where: { //设定异步数据接口的额外参数，任意设
				    	"condition": condition.val(),
// 				    	"page":"1",
// 				    	"limit":"5"
				    }
			  });
			});
		//监听侧边工具条
			 table.on('tool(form1)',function(obj){
				 var item = obj.data;
				 var layEvent = obj.event;
				 //粗略获取系统时间
				 var date = new Date();
				 var nowtime = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
// 				 alert(nowtime);
				 //同意
				 if(layEvent === 'agree'){
	 				 $.ajax({
	 					 url:"../HumanServlet?button=2&status=1&applyid="+item.applyid+"&operater="+item.operater+"&applytype=inputOvertime&overtime="+item.overtime+"&weekovertime="+item.weekovertime+"&festovertime="+item.festovertime
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "1";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
 				 //拒绝
				 }else if(layEvent === 'refuse'){
					 $.ajax({
						 url:"../HumanServlet?button=2&status=2&applyid="+item.applyid+"&operater="+item.operater
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "2";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
				 }
				 obj.update(item);
			 });
//请假旷工
			var tableIns2 = table.render({
				done: function(res, curr, count){
					if(res.data[0].applytype == 'inputOvertime'){
						document.getElementById("applytype1").innerText = "加班申请";
					}else if(res.data[0].applytype == 'inputPunishing'){
						document.getElementById("applytype2").innerText = "请假旷工申请";
					}else if(res.data[0].applytype == 'inputCommission'){
						document.getElementById("applytype3").innerText = "提成申请";
					}else if(res.data[0].applytype == 'inputBonus'){
						document.getElementById("applytype4").innerText = "奖金申请";
					}
				}
			,elem: '#demo2'
			    ,height: 350
			    ,url: '../HumanServlet?button=1&applytype=inputPunishing' //数据接口
		    	,toolbar: '#search2'
			    ,page: true //开启分页
			    ,limit: 5
				,limits:[5,20,50]
			    ,defaultToolbar:["print"]
			    ,cols: [[ //表头
				      {field: 'applyid', title: '申请编号', width:120, sort: true,fixed: 'left'}
				      ,{field: 'applicant', title: '申请人', width:100}
				      ,{field: 'applytime', title: '申请提交时间', width: 180, sort: true}
				      ,{field: 'operater', title: ' 处理对象', width:100}
				      ,{field: 'leavecount', title: '请假次数', width: 220}
				      ,{field: 'absentcount', title: '旷工次数', width: 220}
				      ,{field: 'applydescribe', title: '申请描述', width: 250}
				      ,{field: 'handle', title: '审批人', width: 100}
				      ,{field: 'handletime', title: '审批时间', width: 180, sort: true}
				      ,{field: 'status', title: '审批状态', width:150, templet:'#statusTpl',fixed: 'right'}
				    ]]
		});
		// 顶部工具栏事件
		  table.on('toolbar(form2)', function(obj){
//			  var checkStatus = table.checkStatus(obj.config.id);
			  var data = obj.data;
	    	  var condition = $('#condition2');
// 	    	  var Condition = document.getElementById("condition");
	    	  if(condition.val()==""){
	    		  layer.msg("显示全部请假旷工申请");
	    	  }else if(condition.val()=="0"){
	    		  layer.msg("显示待审核的请假旷工申请");
	    	  }else if(condition.val()=="1"){
	    		  layer.msg("显示审核通过的请假旷工申请");
	    	  }else if(condition.val()=="2"){
	    		  layer.msg("显示审核不通过的请假旷工申请");
	    	  }
	    	  tableIns2.reload({
	    		  url: '../HumanServlet?button=1&applytype=inputPunishing'
				  ,where: { //设定异步数据接口的额外参数，任意设
				    	"condition": condition.val(),
// 				    	"page":"1",
// 				    	"limit":"5"
				    }
			  });
			});
		//监听侧边工具条
			 table.on('tool(form2)',function(obj){
				 var item = obj.data;
				 var layEvent = obj.event;
				 //粗略获取系统时间
				 var date = new Date();
				 var nowtime = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
// 				 alert(nowtime);
				 //同意
				 if(layEvent === 'agree'){
	 				 $.ajax({
	 					 url:"../HumanServlet?button=2&status=1&applyid="+item.applyid+"&operater="+item.operater+"&applytype=inputPunishing&leavecount="+item.leavecount+"&absentcount="+item.absentcount
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "1";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
 				 //拒绝
				 }else if(layEvent === 'refuse'){
					 $.ajax({
						 url:"../HumanServlet?button=2&status=2&applyid="+item.applyid+"&operater="+item.operater
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "2";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
				 }
				 obj.update(item);
			 });
//提成
		var tableIns3 = table.render({
			done: function(res, curr, count){
				if(res.data[0].applytype == 'inputOvertime'){
					document.getElementById("applytype1").innerText = "加班申请";
				}else if(res.data[0].applytype == 'inputPunishing'){
					document.getElementById("applytype2").innerText = "请假旷工申请";
				}else if(res.data[0].applytype == 'inputCommission'){
					document.getElementById("applytype3").innerText = "提成申请";
				}else if(res.data[0].applytype == 'inputBonus'){
					document.getElementById("applytype4").innerText = "奖金申请";
				}
			}
			,elem: '#demo3'
			    ,height: 350
			    ,url: '../HumanServlet?button=1&applytype=inputCommission' //数据接口
		    	,toolbar: '#search3'
			    ,page: true //开启分页
			    ,limit: 5
				,limits:[5,20,50]
			    ,defaultToolbar:["print"]
			    ,cols: [[ //表头
				      {field: 'applyid', title: '申请编号', width:120, sort: true,fixed: 'left'}
				      ,{field: 'applicant', title: '申请人', width:100}
				      ,{field: 'applytime', title: '申请提交时间', width: 200, sort: true}
				      ,{field: 'operater', title: ' 处理对象', width:100}
				      ,{field: 'commission', title: '销售提成', width: 220}
				      ,{field: 'applydescribe', title: '申请描述', width: 280}
				      ,{field: 'handle', title: '审批人', width: 100}
				      ,{field: 'handletime', title: '审批时间', width: 200, sort: true}
				      ,{field: 'status', title: '审批状态', width:180, templet:'#statusTpl3',fixed: 'right'}
				    ]]
		});
		// 顶部工具栏事件
		  table.on('toolbar(form3)', function(obj){
//			  var checkStatus = table.checkStatus(obj.config.id);
			  var data = obj.data;
	    	  var condition = $('#condition3');
// 	    	  var Condition = document.getElementById("condition");
	    	  if(condition.val()==""){
	    		  layer.msg("正在显示全部提成申请");
	    	  }else if(condition.val()=="0"){
	    		  layer.msg("正在显示待审核的提成申请");
	    	  }else if(condition.val()=="1"){
	    		  layer.msg("正在显示审核通过的提成申请");
	    	  }else if(condition.val()=="2"){
	    		  layer.msg("正在显示审核不通过的提成申请");
	    	  }
	    	  tableIns3.reload({
	    		  url: '../HumanServlet?button=1&applytype=inputCommission'
				  ,where: { //设定异步数据接口的额外参数，任意设
				    	"condition": condition.val(),
// 				    	"page":"1",
// 				    	"limit":"5"
				    }
			  });
			});
		//监听侧边工具条
			 table.on('tool(form3)',function(obj){
				 var item = obj.data;
				 var layEvent = obj.event;
				 //粗略获取系统时间
				 var date = new Date();
				 var nowtime = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
// 				 alert(nowtime);
				 //同意
				 if(layEvent === 'agree'){
	 				 $.ajax({
	 					 url:"../HumanServlet?button=2&status=1&applyid="+item.applyid+"&operater="+item.operater+"&applytype=inputCommission&commission="+item.commission
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "1";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
 				 //拒绝
				 }else if(layEvent === 'refuse'){
					 $.ajax({
						 url:"../HumanServlet?button=2&status=2&applyid="+item.applyid+"&operater="+item.operater
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "2";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
				 }
				 obj.update(item);
			 });
//奖金
		var tableIns4 = table.render({
			done: function(res, curr, count){
				if(res.data[0].applytype == 'inputOvertime'){
					document.getElementById("applytype1").innerText = "加班申请";
				}else if(res.data[0].applytype == 'inputPunishing'){
					document.getElementById("applytype2").innerText = "请假旷工申请";
				}else if(res.data[0].applytype == 'inputCommission'){
					document.getElementById("applytype3").innerText = "提成申请";
				}else if(res.data[0].applytype == 'inputBonus'){
					document.getElementById("applytype4").innerText = "奖金申请";
				}
			}
			,elem: '#demo4'
		    ,height: 350
		    ,url: '../HumanServlet?button=1&applytype=inputBonus' //数据接口
	    	,toolbar: '#search4'
		    ,page: true //开启分页
		    ,limit: 5
			,limits:[5,20,50]
		    ,defaultToolbar:["print"]
		    ,cols: [[ //表头
			      {field: 'applyid', title: '申请编号', width:120, sort: true,fixed: 'left'}
			      ,{field: 'applicant', title: '申请人', width:100}
			      ,{field: 'applytime', title: '申请提交时间', width: 180, sort: true}
			      ,{field: 'operater', title: ' 处理对象', width:100}
			      ,{field: 'festivalbonus', title: '节假福利奖', width: 220}
			      ,{field: 'yearbonus', title: '年终奖', width: 220}
			      ,{field: 'applydescribe', title: '申请描述', width: 250}
			      ,{field: 'handle', title: '审批人', width: 100}
			      ,{field: 'handletime', title: '审批时间', width: 180, sort: true}
			      ,{field: 'status', title: '审批状态', width:150, templet:'#statusTpl4',fixed: 'right'}
			    ]]
		});
		// 顶部工具栏事件
		  table.on('toolbar(form4)', function(obj){
//			  var checkStatus = table.checkStatus(obj.config.id);
			  var data = obj.data;
	    	  var condition = $('#condition4');
	    	  var Condition = document.getElementById("condition");
	    	  if(condition.val()==""){
	    		  layer.msg("显示全部奖金申请");
	    	  }else if(condition.val()=="0"){
	    		  layer.msg("显示待审核的奖金申请");
	    	  }else if(condition.val()=="1"){
	    		  layer.msg("显示审核通过的奖金申请");
	    	  }else if(condition.val()=="2"){
	    		  layer.msg("显示审核不通过的奖金申请");
	    	  }
	    	  tableIns4.reload({
	    		  url: '../HumanServlet?button=1&applytype=inputBonus'
				  ,where: { //设定异步数据接口的额外参数，任意设
				    	"condition": condition.val(),
// 				    	"page":"1",
// 				    	"limit":"5"
				    }
			  });
			});
		//监听侧边工具条
			 table.on('tool(form4)',function(obj){
				 var item = obj.data;
				 var layEvent = obj.event;
				 //粗略获取系统时间
				 var date = new Date();
				 var nowtime = date.getFullYear()+"-"+date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
// 				 alert(nowtime);
				 //同意
				 if(layEvent === 'agree'){
	 				 $.ajax({
	 					 url:"../HumanServlet?button=2&status=1&applyid="+item.applyid+"&operater="+item.operater+"&applytype=inputBonus&festivalbonus="+item.festivalbonus+"&yearbonus="+item.yearbonus
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "1";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
 				 //拒绝
				 }else if(layEvent === 'refuse'){
					 $.ajax({
						 url:"../HumanServlet?button=2&status=2&applyid="+item.applyid+"&operater="+item.operater
	 					 ,type:"post"
	 					 ,async:false
	 					 ,data: {}
	 					 ,success:function(res){
	 						 item.status = "2";
	 						 item.handle = "${sessionScope.userid}";
	 						 item.handletime = nowtime;
	 						 layer.msg(res);	//直接得到后端out.println()出的数据
	 					 }
		 				,error:function(res){
							 layer.msg(res);
						 }
	 				 });
				 }
				 obj.update(item);
			 });
	});
	</script>

</div>
</body>
</html>